package cn.edu.scau.cmi.front.dao;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.scau.cmi.ema.dao.AbstractJpaDao;
import cn.edu.scau.cmi.ema.domain.Address;

@Repository("CmiAddressDAO")
@Transactional
public class CmiAddressDAOImpl extends AbstractJpaDao implements CmiAddressDAO{
	@PersistenceContext(unitName = "ema")
	private EntityManager entityManager;
	
	@Override
	public String findAddressNameById(Integer addressId) {
		Query query = createNamedQuery("findAddressNameById", -1, -1,addressId);
		Object object = query.getSingleResult();
		return (String)object;
	}

	@Override
	public EntityManager getEntityManager() {
		// TODO Auto-generated method stub
		return entityManager;
	}

	@Override
	public Set getTypes() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean canBeMerged(Object o) {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public Set<Address> findAddressByLevelAndParent(int level, int parentId) {
		Query query = createNamedQuery("findAddressByLevelAndParent", -1, -1, level, parentId);
		List results = query.getResultList();
		return new LinkedHashSet<Address>(query.getResultList());
	}
	
	


}
